﻿using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Studio
{
	// Token: 0x020004DA RID: 1242
	public class GuideObjectManager : Singleton<GuideObjectManager>
	{
		// Token: 0x17000397 RID: 919
		// (get) Token: 0x06001F97 RID: 8087 RVA: 0x000C3E30 File Offset: 0x000C2030
		public GuideInput guideInput
		{
			get
			{
				return this.m_GuideInput;
			}
		}

		// Token: 0x17000398 RID: 920
		// (get) Token: 0x06001F98 RID: 8088 RVA: 0x000C3E38 File Offset: 0x000C2038
		public DrawLightLine drawLightLine
		{
			get
			{
				return this.m_DrawLightLine;
			}
		}

		// Token: 0x17000399 RID: 921
		// (get) Token: 0x06001F99 RID: 8089 RVA: 0x000C3E40 File Offset: 0x000C2040
		// (set) Token: 0x06001F9A RID: 8090 RVA: 0x000C3E68 File Offset: 0x000C2068
		public GuideObject selectObject
		{
			get
			{
				return (this.hashSelectObject.Count == 0) ? null : this.hashSelectObject.ToArray<GuideObject>()[0];
			}
			set
			{
				this.SetSelectObject(value, true);
			}
		}

		// Token: 0x1700039A RID: 922
		// (get) Token: 0x06001F9B RID: 8091 RVA: 0x000C3E74 File Offset: 0x000C2074
		public GuideObject[] selectObjects
		{
			get
			{
				return (this.hashSelectObject.Count == 0) ? null : this.hashSelectObject.ToArray<GuideObject>();
			}
		}

		// Token: 0x1700039B RID: 923
		// (get) Token: 0x06001F9C RID: 8092 RVA: 0x000C3E98 File Offset: 0x000C2098
		public ChangeAmount[] selectObjectChangeAmount
		{
			get
			{
				return (from v in this.hashSelectObject
				select v.changeAmount).ToArray<ChangeAmount>();
			}
		}

		// Token: 0x1700039C RID: 924
		// (get) Token: 0x06001F9D RID: 8093 RVA: 0x000C3EC8 File Offset: 0x000C20C8
		public int[] selectObjectKey
		{
			get
			{
				return (from v in this.hashSelectObject
				select v.dicKey).ToArray<int>();
			}
		}

		// Token: 0x1700039D RID: 925
		// (get) Token: 0x06001F9E RID: 8094 RVA: 0x000C3EF8 File Offset: 0x000C20F8
		public Dictionary<int, ChangeAmount> selectObjectDictionary
		{
			get
			{
				return this.hashSelectObject.ToDictionary((GuideObject v) => v.dicKey, (GuideObject v) => v.changeAmount);
			}
		}

		// Token: 0x1700039E RID: 926
		// (get) Token: 0x06001F9F RID: 8095 RVA: 0x000C3F4C File Offset: 0x000C214C
		// (set) Token: 0x06001FA0 RID: 8096 RVA: 0x000C3F54 File Offset: 0x000C2154
		public GuideObject operationTarget { get; set; }

		// Token: 0x1700039F RID: 927
		// (get) Token: 0x06001FA1 RID: 8097 RVA: 0x000C3F60 File Offset: 0x000C2160
		public bool isOperationTarget
		{
			get
			{
				return this.operationTarget != null;
			}
		}

		// Token: 0x170003A0 RID: 928
		// (get) Token: 0x06001FA2 RID: 8098 RVA: 0x000C3F70 File Offset: 0x000C2170
		// (set) Token: 0x06001FA3 RID: 8099 RVA: 0x000C3F78 File Offset: 0x000C2178
		public int mode
		{
			get
			{
				return this.m_Mode;
			}
			set
			{
				if (Utility.SetStruct<int>(ref this.m_Mode, value))
				{
					this.SetMode(this.m_Mode);
					if (this.ModeChangeEvent != null)
					{
						this.ModeChangeEvent(this, EventArgs.Empty);
					}
				}
			}
		}

		// Token: 0x06001FA4 RID: 8100 RVA: 0x000C3FB4 File Offset: 0x000C21B4
		public static int GetMode()
		{
			if (!Singleton<GuideObjectManager>.IsInstance())
			{
				return 0;
			}
			return Singleton<GuideObjectManager>.Instance.mode;
		}

		// Token: 0x14000001 RID: 1
		// (add) Token: 0x06001FA5 RID: 8101 RVA: 0x000C3FCC File Offset: 0x000C21CC
		// (remove) Token: 0x06001FA6 RID: 8102 RVA: 0x000C4004 File Offset: 0x000C2204
		public event EventHandler ModeChangeEvent;

		// Token: 0x06001FA7 RID: 8103 RVA: 0x000C403C File Offset: 0x000C223C
		public GuideObject Add(Transform _target, int _dicKey)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectOriginal);
			gameObject.transform.SetParent(this.transformWorkplace);
			GuideObject component = gameObject.GetComponent<GuideObject>();
			component.transformTarget = _target;
			component.dicKey = _dicKey;
			this.dicGuideObject.Add(_target, component);
			Light component2 = _target.GetComponent<Light>();
			if (component2 && component2.type != LightType.Directional)
			{
				this.dicTransLight.Add(_target, component2);
			}
			return component;
		}

		// Token: 0x06001FA8 RID: 8104 RVA: 0x000C40B4 File Offset: 0x000C22B4
		public void Delete(GuideObject _object, bool _destroy = true)
		{
			if (_object == null)
			{
				return;
			}
			if (this.hashSelectObject.Contains(_object))
			{
				this.SetSelectObject(null, false);
			}
			this.dicGuideObject.Remove(_object.transformTarget);
			this.dicTransLight.Remove(_object.transformTarget);
			this.dicGuideLight.Remove(_object);
			if (_destroy)
			{
				UnityEngine.Object.DestroyImmediate(_object.gameObject);
			}
			if (this.operationTarget == _object)
			{
				this.operationTarget = null;
			}
		}

		// Token: 0x06001FA9 RID: 8105 RVA: 0x000C4144 File Offset: 0x000C2344
		public void DeleteAll()
		{
			this.hashSelectObject.Clear();
			this.operationTarget = null;
			GameObject[] array = (from v in this.dicGuideObject
			where v.Value != null
			select v.Value.gameObject).ToArray<GameObject>();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i])
				{
					UnityEngine.Object.DestroyImmediate(array[i]);
				}
			}
			this.dicGuideObject.Clear();
			this.dicTransLight.Clear();
			this.dicGuideLight.Clear();
			this.drawLightLine.Clear();
			this.guideInput.Stop();
		}

		// Token: 0x06001FAA RID: 8106 RVA: 0x000C4214 File Offset: 0x000C2414
		public void SetScale()
		{
			foreach (KeyValuePair<Transform, GuideObject> keyValuePair in this.dicGuideObject)
			{
				keyValuePair.Value.SetScale();
			}
		}

		// Token: 0x06001FAB RID: 8107 RVA: 0x000C4278 File Offset: 0x000C2478
		private void SetMode(int _mode)
		{
			foreach (GuideObject guideObject in this.hashSelectObject)
			{
				guideObject.SetMode(_mode, true);
			}
		}

		// Token: 0x06001FAC RID: 8108 RVA: 0x000C42D8 File Offset: 0x000C24D8
		private void SetSelectObject(GuideObject _object, bool _multiple = true)
		{
			if (_multiple && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)))
			{
				if (_object == null)
				{
					return;
				}
				if (this.hashSelectObject.Contains(_object))
				{
					return;
				}
				if (this.hashSelectObject.Count != 0 && !_object.enableMaluti)
				{
					return;
				}
				this.AddObject(_object, this.hashSelectObject.Count == 0);
			}
			else
			{
				int selectedState = Studio.optionSystem.selectedState;
				if (selectedState != 0)
				{
					if (selectedState == 1)
					{
						GuideObject selectObject = this.selectObject;
						if (!(selectObject == null))
						{
							if (!selectObject.isChild)
							{
								if (_object && _object.isChild)
								{
									selectObject.SetActive(false, false);
								}
								else
								{
									this.StopSelectObject();
								}
							}
							else
							{
								selectObject.SetActive(false, false);
							}
						}
					}
				}
				else
				{
					this.StopSelectObject();
				}
				this.hashSelectObject.Clear();
				if (_object && !_object.enables[this.m_Mode])
				{
					for (int i = 0; i < 3; i++)
					{
						if (_object.enables[i])
						{
							this.mode = i;
							break;
						}
					}
				}
				this.AddObject(_object, true);
			}
			this.guideInput.guideObject = _object;
		}

		// Token: 0x06001FAD RID: 8109 RVA: 0x000C4450 File Offset: 0x000C2650
		private void StopSelectObject()
		{
			foreach (GuideObject guideObject in this.hashSelectObject)
			{
				guideObject.isActive = false;
				Light light = null;
				if (this.dicGuideLight.TryGetValue(guideObject, out light))
				{
					this.drawLightLine.Remove(light);
					this.dicGuideLight.Remove(guideObject);
				}
			}
		}

		// Token: 0x06001FAE RID: 8110 RVA: 0x000C44DC File Offset: 0x000C26DC
		private void AddObject(GuideObject _object, bool _active = true)
		{
			if (_object == null)
			{
				return;
			}
			if (_active)
			{
				_object.isActive = true;
			}
			Light light = null;
			if (this.dicTransLight.TryGetValue(_object.transformTarget, out light))
			{
				this.drawLightLine.Add(light);
				this.dicGuideLight.Add(_object, light);
			}
			this.hashSelectObject.Add(_object);
		}

		// Token: 0x06001FAF RID: 8111 RVA: 0x000C4544 File Offset: 0x000C2744
		protected override void Awake()
		{
			if (!base.CheckInstance())
			{
				return;
			}
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			if (this.transformWorkplace == null)
			{
				this.transformWorkplace = base.transform;
			}
			this.operationTarget = null;
		}

		// Token: 0x0400214C RID: 8524
		[SerializeField]
		private GameObject objectOriginal;

		// Token: 0x0400214D RID: 8525
		[SerializeField]
		private GuideInput m_GuideInput;

		// Token: 0x0400214E RID: 8526
		[SerializeField]
		private Transform transformWorkplace;

		// Token: 0x0400214F RID: 8527
		[SerializeField]
		private DrawLightLine m_DrawLightLine;

		// Token: 0x04002150 RID: 8528
		private HashSet<GuideObject> hashSelectObject = new HashSet<GuideObject>();

		// Token: 0x04002152 RID: 8530
		private int m_Mode;

		// Token: 0x04002154 RID: 8532
		private Dictionary<Transform, GuideObject> dicGuideObject = new Dictionary<Transform, GuideObject>();

		// Token: 0x04002155 RID: 8533
		private Dictionary<Transform, Light> dicTransLight = new Dictionary<Transform, Light>();

		// Token: 0x04002156 RID: 8534
		private Dictionary<GuideObject, Light> dicGuideLight = new Dictionary<GuideObject, Light>();
	}
}
